
package com.avrio.json;

// <editor-fold defaultstate="collapsed" desc="import">
import java.io.IOException;
// </editor-fold>

@SuppressWarnings("serial")
public class JsonNumber extends JsonValue {

    private final String string;

// <editor-fold defaultstate="collapsed" desc="JsonNumber()">

    public JsonNumber(String string) {

        if(string == null) {
            throw new NullPointerException("string is null");
        }
        this.string = string;
    }
// </editor-fold>

// <editor-fold defaultstate="collapsed" desc="toString()">

    @Override
    public String toString() {
        return string;
    }
// </editor-fold>

// <editor-fold defaultstate="collapsed" desc="write()">

    @Override
    protected void write(JsonWriter writer) throws IOException {
        writer.write(string);
    }
// </editor-fold>

// <editor-fold defaultstate="collapsed" desc="isNumber()">

    @Override
    public boolean isNumber() {
        return true;
    }
// </editor-fold>

// <editor-fold defaultstate="collapsed" desc="asInt()">

    @Override
    public int asInt() {
        return Integer.parseInt(string, 10);
    }
// </editor-fold>

// <editor-fold defaultstate="collapsed" desc="asLong()">

    @Override
    public long asLong() {
        return Long.parseLong(string, 10);
    }
// </editor-fold>

// <editor-fold defaultstate="collapsed" desc="asFloat()">

    @Override
    public float asFloat() {
        return Float.parseFloat(string);
    }
// </editor-fold>

// <editor-fold defaultstate="collapsed" desc="asDouble()">

    @Override
    public double asDouble() {
        return Double.parseDouble(string);
    }
// </editor-fold>

// <editor-fold defaultstate="collapsed" desc="hashCode()">

    @Override
    public int hashCode() {
        return string.hashCode();
    }
// </editor-fold>

// <editor-fold defaultstate="collapsed" desc="equals()">

    @Override
    public boolean equals(Object object) {

        if(this == object) {
            return true;
        }
        if(object == null) {
            return false;
        }
        if(getClass() != object.getClass()) {
            return false;
        }

        JsonNumber other = (JsonNumber) object;
        return string.equals(other.string);
    }
// </editor-fold>

}
